package org.lynn.money;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.util.Arrays;

/**
 * @author gy
 * @date 2019/6/22 11:23
 */
public class AlgoVisualizer {

    /**
     * 数据
     */
    private int[] moeny;
    /**
     * 视图
     */
    private AlgoFrame frame;

    public AlgoVisualizer(int sceneWidth, int sceneHeight) {

        // 初始化数据
        moeny = new int[100];
        for (int i = 0; i < moeny.length; i++) {
            moeny[i] = 100;
        }

        // 初始化视图
        EventQueue.invokeLater(() -> {
            frame = new AlgoFrame("Welcome", sceneWidth, sceneHeight);
            new Thread(() -> {
                run();
            }).start();
        });
    }

    /**
     * 动画逻辑
     */
    private void run() {

        while (true) {
            Arrays.sort(moeny);
            frame.render(moeny);
            AlgoVisHelper.pause(40);

            for (int k = 0; k < moeny.length; k++) {
                for (int i = 0; i < moeny.length; i++) {
                    int j = (int) (Math.random() * moeny.length);
                    moeny[i] -= 1;
                    moeny[j] += 1;
                }
            }


        }

    }

    private class AlgoKeyListener extends KeyAdapter {
    }

    private class AlgoMouseListener extends MouseAdapter {
    }

    public static void main(String[] args) {

        int sceneWidth = 1000;
        int sceneHeight = 1000;

        AlgoVisualizer visualizer = new AlgoVisualizer(sceneWidth, sceneHeight);
    }
}

